# coding: utf-8

import numpy as np
import pandas as pd


import scipy.spatial.distance as dist


# 读取数据 
index_df = pd.read_csv('../data/sh_000001_20200101_20230901.csv')

#目标列
tar_col = ['open','high','low','close', 'volume']
tar_df = index_df[tar_col]
tar_df['volume'] = tar_df['volume'].astype('float')

#归一化
tar_df = tar_df.apply(lambda x: (x - np.min(x)) / (np.max(x) - np.min(x)))

#获得第1行
ori = tar_df.iloc[0]
#获得第2-6行
tar_df = tar_df.iloc[1:6]

#dataframe内两两计算
print(dist.pdist(tar_df, "euclidean"))

#计算第1行与其他行的余弦相似度
for index, row in tar_df.iterrows():
    print(dist.cosine(ori, row))



# 绘图的matplotlib库
import matplotlib.pyplot as plt

#初始化图像
#fig = plt.figure(figsize=(3.0,3.0))
#新建画图区
#ax = fig.add_axes([0, 0, 1, 1])

y = index_df['open'].iloc[:100]
x = np.arange(0, 100)

#折线图
plt.plot(x, y,label='line')

#散点图
plt.scatter(x,y,marker='s', label='scatter')

#绘制图例
plt.legend()

#设置标题
plt.title("Test Figure")

#设置x轴标题
plt.xlabel('x')
#设置y轴标题
plt.ylabel('y')

#生成图片
plt.savefig('test2.png')

